package com.eh.proxy.authority.handler;

import com.eh.proxy.authority.model.PersonBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by David on 2016/5/3.
 */
public class NonOwnerInvocationHandler implements InvocationHandler {
    private PersonBean personBean;

    public NonOwnerInvocationHandler(PersonBean personBean) {
        this.personBean = personBean;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().equals("setHotOrNotRating") || method.getName().startsWith("get")) {
            try {
                return method.invoke(personBean, args);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
        throw new IllegalAccessException();
    }
}
